# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.http import HttpResponse
from .models import Article,Publication

from django.shortcuts import render

# Create your views here.
def many_to_many(request):
    p1 = Publication(title='The Python Journal')   #创建publication对象
    p2 = Publication(title='Science News')
    p3 = Publication(title='Science Weekly')
    p1.save()     #保存数据
    p2.save()
    p3.save()

    a1 = Article(headline='Django lets you build Web apps easily')   #创建article对象
    a2 = Article(headline='NASA uses Python')
    a3 = Article(headline='NASA apps Python')
    a1.save()      #保存数据
    a2.save()
    a3.save()

    a1.publications.add(p1) #为article和publication对象建立关联


    return HttpResponse('success')
